﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
using System.Threading.Tasks;

namespace Linq
{
     public class MyContext : DbContext//DcContext来自EF框架
    {
        ///// <summary>
        ///// 构造函数
        ///// 执行父类DbContext的构造函数
        ///// </summary>
        ///// <param name="options"></param>
        //public MyContext(DbContextOptions<MyContext> options) : base(options)
        //{

        //}

        //创建虚属性
        public virtual DbSet<Student> Students { get; set; }
        public virtual DbSet<Score> Scores { get; set; }


        //重写父类方法时不能给改父类的访问修饰符(因为没有必要，所以C#不允许你给改变访问级别)
        protected  override void OnConfiguring(DbContextOptionsBuilder options)
        {
            options.UseSqlServer("server=YB\\LY;database=Linq;User ID=sa;pwd=yubing1990;Trust Server Certificate=True");
        }

    }


    [Table("Student")]
    [PrimaryKey("Id")]
    /// <summary>
    /// 学生类
    /// </summary>
    public class Student
    {
        
        public int Id { get; set; }
        public string StudentName { get; set; }
        public string Sex { get; set; }
        public int ClassId { get; set; }
        public Nullable<System.DateTime> Birthday { get; set; }
    }

    [Table("Score")]
    [PrimaryKey("Id")]
    /// <summary>
    /// 分数类
    /// </summary>
    public class Score
    { 
        public int Id { get; set; }
        public string Course { get; set; }
        public int StudentId { get; set; }
        public Nullable<int> Degree { get; set; }
    }

   

    /// <summary>
    /// DTO  数据传输对象
    /// </summary>
    public class StudnetDto
    {
        public int Id { get; set; }
        public string? NickName { get; set; }
        public string? Gender { get; set; }
        public int ClassId { get; set; }
        public DateTime? Birthday { get; set; }
    }
}
